#import "SEGPraiseorcollectManager.h"

#if __has_include(<Commom/SEGModel.h>)
#import <Commom/SEGModel.h>
#else
#import "SEGModel.h"
#endif

#if __has_include(<Commom/SEGHTTPBusinessManager.h>)
#import <Commom/SEGHTTPBusinessManager.h>
#else
#import "SEGHTTPBusinessManager.h"
#endif

#if __has_include(<Commom/SEGAnalyseBehaviorManager.h>)
#import <Commom/SEGAnalyseBehaviorManager.h>
#else
#import "SEGAnalyseBehaviorManager.h"
#endif

#if __has_include(<SEGPlatform/SEGBussinessConstHeader.h>)
#import <SEGPlatform/SEGBussinessConstHeader.h>
#else
#import "SEGBussinessConstHeader.h"
#endif

#if __has_include(<Commom/SEGProfileManager.h>)
#import <Commom/SEGProfileManager.h>
#else
#import "SEGProfileManager.h"
#endif

static id _PraiseOrCollectManager;
static dispatch_once_t onceToken;

@implementation SEGPraiseorcollectManager
#pragma mark - SINGLE----BEGIN----
+(instancetype)sharedManager{
    dispatch_once(&onceToken, ^{
        _PraiseOrCollectManager = [[self alloc] init];
    });
    return _PraiseOrCollectManager;
}

+(void)destroyResource{
    onceToken = 0;
    _PraiseOrCollectManager = nil;
}

#pragma mark - SINGLE----END----

#pragma mark - HTTP----BEGIN----
/**
 * 取消点赞
 * @author Wendy
 * @param objId 被取消对象ID
 * @param objType 被取消对象类型
 * @param finished 回调结果
 */
- (void)requestCancelPraiseByobjId:(NSString*)objId
                           objType:(NSString*)objType
                            userId:(NSString*)userId
                              type:(NSString*)type
                          finished:(void(^)(BOOL isSuccessed,id result,NSString* codeType,NSString* errorMessage))finished{
    
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setValue:userId forKey:@"userId"];
    [params setValue:objId forKey:@"objId"];
    [params setValue:objType forKey:@"objType"];
    [params setValue:type forKey:@"type"];
    
    NSString *urlString = [SEGServerManager serverUrlJoint:kClientRootURL,@"/",kCMS_api,@"/praiseAttent/cancelPraiseOrCollect.json",nil];
    [SEGHTTPBusinessManager seg_requestWithMethod:POST URLString:urlString parameters:params completed:^(BOOL isSuccessed, id result, NSString *codeType, NSError *error) {
        if (!isSuccessed) {
            finished(isSuccessed,nil,codeType,error.localizedDescription);
            return;
        }
        
        [[SEGAnalyseBehaviorManager sharedManager] requestIntegralGrowthWithCode:SEGIntegralCode.cancelLike finished:^(BOOL isSuccessed, id result, NSString *codeType, NSString *errorMessage) {
        }];
        
        //self.PraiseOrCollect = [SEGPraiseorcollectModel yy_modelWithDictionary:result];
        finished(isSuccessed,result,codeType,error.localizedDescription);
        return;
    }];
}

/**
 * 对评论点赞
 * @author Wendy
 * @param objId    被点赞或浏览主题对象
 * @param objType  被点赞或浏览主题对象类型 1 画报2问题 3评论 4问题答案
 * @param objPicUrlForMsg  消息图片 主要是 2手 闲置 帮帮
 * @param objTitleForMsg  消息标题,如果是对PGC或者话题等系统发起的 objTitleForMsg为对应的标题，帮帮则为帮帮的标题（即问题的内容）否则objTitleForMsg为 评论内容
 * @param byReviewUserId  被点赞对象的用户ID，即记录创建者的用户Id
 * @param parentObjId    父级Id ，例如对问题答案进行回复的话 parentObjId为问题ID
 * @param parentObjType
 * @param operationType 邻里圈类型 邻里圈相关点赞传 其他地方不传
 * @param isParent 是否是对主数据进行评论 1：是 2：不是
 * @param finished 回调结果
 */
- (void)requestPraiseAttentByObjId:(NSString*)objId
                           ObjType:(NSString*)objType
                   objPicUrlForMsg:(NSString*)objPicUrlForMsg
                    objTitleForMsg:(NSString*)objTitleForMsg
                    byReviewUserId:(NSString*)byReviewUserId
                       parentObjId:(NSString*)parentObjId
                     parentObjType:(NSString*)parentObjType
                     operationType:(NSString *)operationType
                          isParent:(NSString *)isParent
                          finished:(void(^)(BOOL isSuccessed,id result,NSString* codeType,NSString* errorMessage))finished{
    
    //字典为空的闪退，数据校验
    NSDictionary* tempDict = @{
                               @"objId" : objId,
                               @"objType" : objType,
                               @"type" : @"1",//点赞固定1
                               @"creator" : [SEGProfileManager sharedManager].profile.nickname,
                               @"objTitleForMsg" : objTitleForMsg,
                               @"byReviewUserId" : byReviewUserId,
                               @"communityName" : [SEGProfileManager sharedManager].profile.communityName,
                               @"parentObjId" : parentObjId,
                               @"userId" : kAccountUserID,
                               @"parentObjType" : parentObjType
                               };
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:tempDict];
    if (objPicUrlForMsg) {
        [params setObject:objPicUrlForMsg forKey:@"objPicUrlForMsg"];
    }
    if (operationType) {
        [params setObject:operationType forKey:@"operationType"];
    }
    if (isParent) {
        [params setObject:isParent forKey:@"isParent"];
    }
    
    NSString *urlString = [SEGServerManager serverUrlJoint:kClientRootURL,@"/",kCMS_api,@"/praiseAttent/save.json",nil];
    [SEGHTTPBusinessManager seg_requestWithMethod:POST URLString:urlString parameters:params completed:^(BOOL isSuccessed, id result, NSString *codeType, NSError *error) {
        if (!isSuccessed) {
            finished(isSuccessed,nil,codeType,error.localizedDescription);
            return;
        }
        
        [[SEGAnalyseBehaviorManager sharedManager] requestIntegralGrowthWithCode:SEGIntegralCode.like finished:^(BOOL isSuccessed, id result, NSString *codeType, NSString *errorMessage) {
        }];
        
        //self.PraiseOrCollect = [SEGPraiseorcollectModel yy_modelWithDictionary:result];
        finished(isSuccessed,result,codeType,error.localizedDescription);
        return;
    }];
}


#pragma mark - HTTP----END----

#pragma mark - GETTER----BEGIN----
-(SEGPraiseorcollectModel *)PraiseOrCollect{
    if (!_PraiseOrCollect) {
        _PraiseOrCollect = [[SEGPraiseorcollectModel alloc]init];
    }
    return _PraiseOrCollect;
}
#pragma mark - GETTER----END----
@end


